home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / ixnet / start.s < prev    next >
Text File  |  1996-03-13  |  8KB  |  282 lines

  1. /*
  2.  *  This file is part of ixnet.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #define START
  22. #include "ixnet.h"
  23. #include "version.h"
  24.  
  25. /* size of C_PRIVATE was generated by create_header.c */
  26. /* include the generated header */
  27. #include "ix_internals.h"
  28.  
  29.  
  30.     .text
  31.  
  32.    | The first executable location.  This should return an error
  33.    | in case someone tried to run you as a program (instead of
  34.    | loading you as a library).
  35.     .globl    Start        | we use this to force inclusion of start.s
  36. Start:
  37.    movel   #-1,d0
  38.    rts
  39.  
  40. |-----------------------------------------------------------------------
  41. | A romtag structure.  Both "exec" and "ramlib" look for
  42. | this structure to discover magic constants about you
  43. | (such as where to start running you from...).
  44. |-----------------------------------------------------------------------
  45.  
  46. initDDescrip:
  47.            |STRUCTURE RT,0
  48.      .word    RTC_MATCHWORD     | UWORD RT_MATCHWORD
  49.      .long    initDDescrip     | APTR  RT_MATCHTAG
  50.      .long    EndCode         | APTR  RT_ENDSKIP
  51.      .byte    RTF_AUTOINIT     | UBYTE RT_FLAGS
  52.      .byte    IXNET_VERSION     | UBYTE RT_VERSION
  53.      .byte    NT_LIBRARY     | UBYTE RT_TYPE
  54.      .byte    IXNET_PRIORITY     | BYTE  RT_PRI
  55.      .long    ixName         | APTR  RT_NAME
  56.      .long    idString         | APTR  RT_IDSTRING
  57.      .long    Init         | APTR  RT_INIT
  58. | this is just fool proof, and this library will never make it to ROM
  59. | anyway, so resident tags are not that important ;-)
  60. EndCode:
  61.  
  62.  
  63.    | this is the name that the library will have
  64. ixName:    .asciz IXNET_NAME
  65.  
  66.    | this is an identifier tag to help in supporting the library
  67.    | format is 'name version.revision (dd.mm.yy)',<cr>,<lf>,<null>'
  68.    | without any leading zeros in dd.mm.yy
  69. idString:
  70.     .ascii IXNET_IDSTRING
  71.     .byte 13
  72.     .byte 10
  73.     .byte 0
  74.  
  75.    | force word alignment
  76.    .even
  77.  
  78.  
  79.    | The romtag specified that we were "RTF_AUTOINIT".  This means
  80.    | that the RT_INIT structure member points to one of these
  81.    | tables below.  If the AUTOINIT bit was not set then RT_INIT
  82.    | would point to a routine to run.
  83.  
  84. Init:
  85.    .long   IXNETBASE_SIZEOF       | size of library base data space
  86.    .long   funcTable        | pointer to function initializers
  87.    .long   dataTable        | pointer to data initializers
  88.    .long   initRoutine        | routine to run
  89.  
  90.  
  91. funcTable:
  92.  
  93.    |------ standard system routines
  94.    .long   Open
  95.    .long   Close
  96.    .long   Expunge
  97.    .long   Null
  98.  
  99.    |------ my libraries definitions
  100.  
  101. #define SYSTEM_CALL(func, vec) .long _/**/func
  102. #include <sys/ixnet_syscall.def>
  103. #undef SYSTEM_CALL
  104.  
  105.    |------ function table end marker
  106.    .long   -1
  107.  
  108.  
  109.    | The data table initializes static data structures.
  110.    | The format is specified in exec/InitStruct routines
  111.    | manual pages.  The INITBYTE/INITWORD/INITLONG routines
  112.    | are in the file "exec/initializers.i".  The first argument
  113.    | is the offset from the library base for this byte/word/long.
  114.    | The second argument is the value to put in that cell.
  115.    | The table is null terminated
  116.    | NOTE - LN_TYPE below is a correction - old example had LH_TYPE
  117.  
  118. dataTable:
  119.     INITBYTE (LN_TYPE,              NT_LIBRARY)
  120.     INITLONG (LN_NAME,              ixName)
  121.     INITBYTE (IXNETBASE_FLAGS,      0x6) |LIBF_CHANGED_SUMUSED
  122.     INITWORD (IXNETBASE_VERSION,    IXNET_VERSION)
  123.     INITWORD (IXNETBASE_REVISION,   IXNET_REVISION)
  124.     INITLONG (IXNETBASE_IDSTRING,   idString)
  125.     .long    0
  126.  
  127.  
  128. #ifdef DEBUG
  129. twoint:
  130.     .asciz "$%lx, $%lx\n"
  131. #endif
  132.  
  133.    | This routine gets called after the library has been allocated.
  134.    | The library pointer is in D0.  The segment list is in A0.
  135.    | If it returns non-zero then the library will be linked into
  136.    | the library list.
  137. initRoutine:
  138.  
  139.    |------ get the library pointer into a convenient A register
  140.    movel   a5,sp@-
  141.    movel   d0,a5
  142.  
  143.    |------ save a pointer to our loaded code
  144.    movel   a0,a5@(IXNETBASE_SEGLIST)
  145.  
  146.    |------ do the higher-level initialization in C
  147.    pea       a5@
  148.    jbsr    _ixnet_init
  149.    lea       sp@(4),sp
  150.    movel   sp@+,a5
  151.    rts
  152.  
  153. |----------------------------------------------------------------------
  154. |
  155. | here begins the system interface commands.  When the user calls
  156. | OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  157. | into a call to the following routines (Open/Close/Expunge).  Exec
  158. | has already put our library pointer in A6 for us.  Exec has turned
  159. | off task switching while in these routines (via Forbid/Permit), so
  160. | we should not take too long in them.
  161. |
  162. |----------------------------------------------------------------------
  163.  
  164.  
  165.    | Open returns the library pointer in d0 if the open
  166.    | was successful.  If the open failed then null is returned.
  167.    | It might fail if we allocated memory on each open, or
  168.    | if only open application could have the library open
  169.    | at a time...
  170.  
  171. Open:       | ( libptr:a6, version:d0 )
  172.  
  173.  
  174.    |------ mark us as having another opener
  175.    addw   #1,a6@(IXNETBASE_OPENCNT)
  176.  
  177.    |------ prevent delayed expunges
  178.    | !!!!!!
  179.    | commo - example code uses private flags field (IXNETBASE_MYFLAGS), WHY????
  180.    | !!!!!!
  181.    bclr   #LIBB_DELEXP,a6@(IXNETBASE_FLAGS)
  182.  
  183.    |------ do other things in C
  184.    pea       a6@
  185.    jbsr    _ixnet_open
  186.    lea       sp@(4),sp
  187.    |--- ix_open() should return the library base, if all ok
  188.  
  189.    rts
  190.  
  191.    | There are two different things that might be returned from
  192.    | the Close routine.  If the library is no longer open and
  193.    | there is a delayed expunge then Close should return the
  194.    | segment list (as given to Init).  Otherwise close should
  195.    | return NULL.
  196.  
  197. Close:        | ( libptr:a6 )
  198.  
  199.    |------ do any cleanups needed in C
  200.    pea      a6@
  201.    jsr      _ixnet_close
  202.    lea      sp@(4),sp
  203.  
  204.    |------ set the return value
  205.    clrl   d0
  206.  
  207.    |------ mark us as having one fewer openers
  208.    subw   #1,a6@(IXNETBASE_OPENCNT)
  209.  
  210.    |------ see if there is anyone left with us open
  211.    bne      L11
  212.  
  213.    |------ see if we have a delayed expunge pending
  214.    btst   #LIBB_DELEXP,a6@(IXNETBASE_FLAGS)        | SEE ABOVE!
  215.    beq      L11
  216.  
  217.    |------ do the expunge
  218.    bsr      Expunge
  219. L11:
  220.    rts
  221.  
  222.  
  223.    | There are two different things that might be returned from
  224.    | the Expunge routine.  If the library is no longer open
  225.    | then Expunge should return the segment list (as given to
  226.    | Init).  Otherwise Expunge should set the delayed expunge
  227.    | flag and return NULL.
  228.    |
  229.    | One other important note: because Expunge is called from
  230.    | the memory allocator, it may NEVER Wait() or otherwise
  231.    | take long time to complete.
  232.  
  233. Expunge:   | ( libptr: a6 )
  234.    moveml  d2/a5/a6,sp@-
  235.    movel   a6,a5
  236.    movel   4:w,a6
  237.  
  238.    |------ see if anyone has us open
  239.    tstw    a5@(IXNETBASE_OPENCNT)
  240.    beq       L21
  241.  
  242.    |------ it is still open.  set the delayed expunge flag
  243.    bset    #LIBB_DELEXP,a5@(IXNETBASE_FLAGS)       | SEE ABOVE !!
  244.    clrl    d0
  245.    bra       Expunge_End
  246.  
  247. L21:
  248.    |------ go ahead and get rid of us.    Store our seglist in d2
  249.    movel   a5@(IXNETBASE_SEGLIST),d2
  250.  
  251.    |------ unlink from library list
  252.    movel   a5,a1
  253.    jsr       a6@(_LVORemove)
  254.  
  255.    |
  256.    | device specific closings here...
  257.    |
  258.    pea       a5@
  259.    jsr       _ixnet_expunge
  260.    lea       sp@(4),sp
  261.  
  262.    |------ free our memory
  263.    clrl    d0
  264.    movel   a5,a1
  265.    movew   a5@(IXNETBASE_NEGSIZE),d0
  266.  
  267.    subl    d0,a1
  268.    addw    a5@(IXNETBASE_POSSIZE),d0
  269.  
  270.    jsr       a6@(_LVOFreeMem)
  271.  
  272.    |------ set up our return value
  273.    movel   d2,d0
  274.  
  275. Expunge_End:
  276.    moveml  sp@+,d2/a5/a6
  277.    rts
  278.  
  279. Null:
  280.    clrl    d0
  281.    rts
  282.